{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:25:46.898512Z",
     "start_time": "2019-12-02T13:25:46.887254Z"
    }
   },
   "outputs": [],
   "source": [
    "#调试开关\n",
    "import logging\n",
    "\n",
    "#添加系统路径\n",
    "import sys\n",
    "sys.path.append(\"../AdvBox/\")\n",
    "\n",
    "import torch\n",
    "import torchvision\n",
    "import torch.nn as nn\n",
    "from torchvision import datasets, transforms\n",
    "import torch.utils.data.dataloader as Data\n",
    "from advbox.adversary import Adversary\n",
    "from advbox.attacks.gradient_method import FGSM\n",
    "from advbox.models.pytorch import PytorchModel\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "# 自适应使用GPU还是CPU\n",
    "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:25:47.165186Z",
     "start_time": "2019-12-02T13:25:47.149086Z"
    }
   },
   "outputs": [],
   "source": [
    "# 训练mnist的cnn网络定义\n",
    "class Net(nn.Module):\n",
    "    def __init__(self):\n",
    "        super(Net, self).__init__()\n",
    "        self.conv1 = nn.Sequential(   # (1,28,28)   \n",
    "            # in_channels:输入的通道数， out_channels：卷积核数量， kernel_size：卷积核大小， stride：步长\n",
    "            # stride=1时， padding=(kernel_size-1)/2， 图片长宽不变\n",
    "            nn.Conv2d(in_channels=1, out_channels=16, kernel_size=5, stride=1, padding=2),    # (16,28,28)\n",
    "            nn.ReLU(),\n",
    "            nn.MaxPool2d(kernel_size=2),    # (16,14,14)\n",
    "        )\n",
    "        self.conv2 = nn.Sequential(\n",
    "            nn.Conv2d(in_channels=16, out_channels=32, kernel_size=5, stride=1, padding=2),    # (32,14,14)\n",
    "            nn.ReLU(),\n",
    "            nn.MaxPool2d(kernel_size=2),    # （32,7,7）\n",
    "        )\n",
    "        self.fc1 = nn.Sequential(\n",
    "            nn.Linear(32*7*7, 500),\n",
    "            nn.ReLU()\n",
    "        )\n",
    "        self.fc2 = nn.Linear(500, 10)\n",
    "        \n",
    "    def forward(self, x):\n",
    "        x = self.conv1(x)\n",
    "        x = self.conv2(x)    # (batch,32,7,7)\n",
    "        x = x.view(x.size(0), -1)    # (batch,32*7*7)\n",
    "        x = self.fc1(x)\n",
    "        output = self.fc2(x)\n",
    "        return output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:25:47.403910Z",
     "start_time": "2019-12-02T13:25:47.388951Z"
    }
   },
   "outputs": [],
   "source": [
    "class AutoEncoder(nn.Module):\n",
    "    def __init__(self):\n",
    "        super(AutoEncoder, self).__init__()\n",
    "\n",
    "        self.encoder = nn.Sequential(\n",
    "            nn.Conv2d(1,64,kernel_size=3,stride=1,padding=1),\n",
    "            nn.ReLU(),\n",
    "            nn.MaxPool2d(kernel_size=2,stride=2),\n",
    "            nn.Conv2d(64,128,kernel_size=3,stride=1,padding=1),\n",
    "            nn.ReLU(),\n",
    "            nn.MaxPool2d(kernel_size=2,stride=2),\n",
    "        )\n",
    "        self.decoder = nn.Sequential(\n",
    "            nn.Upsample(scale_factor=2,mode=\"nearest\"),\n",
    "            nn.Conv2d(128,64,kernel_size=3,stride=1,padding=1),\n",
    "            nn.ReLU(),\n",
    "            nn.Upsample(scale_factor=2,mode=\"nearest\"),\n",
    "            nn.Conv2d(64,1,kernel_size=3,stride=1,padding=1),\n",
    "        )\n",
    "\n",
    "    def forward(self, x):\n",
    "        output = self.encoder(x)\n",
    "        output = self.decoder(output)\n",
    "        return output"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:25:47.652270Z",
     "start_time": "2019-12-02T13:25:47.610498Z"
    }
   },
   "outputs": [],
   "source": [
    "autoencoder = AutoEncoder().to(device)\n",
    "\n",
    "optimizer = torch.optim.Adam(autoencoder.parameters(), lr=0.01)\n",
    "loss_func = nn.MSELoss()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:25:48.293359Z",
     "start_time": "2019-12-02T13:25:48.229746Z"
    }
   },
   "outputs": [],
   "source": [
    "#使用MNIST训练数据集 \n",
    "train_data=datasets.MNIST('/home/shenchenkai/data/mnist_pytorch/', train=True, download=False, transform=transforms.Compose([\n",
    "        transforms.ToTensor(),\n",
    "    ]))\n",
    "\n",
    "train_loader = torch.utils.data.DataLoader(\n",
    "    dataset=train_data,\n",
    "    batch_size=128, shuffle=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:27:29.101469Z",
     "start_time": "2019-12-02T13:25:48.964084Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch=1 batch=100 loss=0.03581857308745384\n",
      "Epoch=1 batch=200 loss=0.0293037798255682\n",
      "Epoch=1 batch=300 loss=0.029111456125974655\n",
      "Epoch=1 batch=400 loss=0.028390636667609215\n",
      "Epoch=2 batch=100 loss=0.027548573911190033\n",
      "Epoch=2 batch=200 loss=0.02530878223478794\n",
      "Epoch=2 batch=300 loss=0.025680825114250183\n",
      "Epoch=2 batch=400 loss=0.024080397561192513\n",
      "Epoch=3 batch=100 loss=0.026186615228652954\n",
      "Epoch=3 batch=200 loss=0.023570651188492775\n",
      "Epoch=3 batch=300 loss=0.02365405671298504\n",
      "Epoch=3 batch=400 loss=0.02442971058189869\n",
      "Epoch=4 batch=100 loss=0.025155559182167053\n",
      "Epoch=4 batch=200 loss=0.023913631215691566\n",
      "Epoch=4 batch=300 loss=0.02372409589588642\n",
      "Epoch=4 batch=400 loss=0.02442202717065811\n",
      "Epoch=5 batch=100 loss=0.024600552394986153\n",
      "Epoch=5 batch=200 loss=0.024714380502700806\n",
      "Epoch=5 batch=300 loss=0.023196186870336533\n",
      "Epoch=5 batch=400 loss=0.023859839886426926\n",
      "Epoch=6 batch=100 loss=0.023595696315169334\n",
      "Epoch=6 batch=200 loss=0.023206466808915138\n",
      "Epoch=6 batch=300 loss=0.023420490324497223\n",
      "Epoch=6 batch=400 loss=0.023415153846144676\n",
      "Epoch=7 batch=100 loss=0.024173829704523087\n",
      "Epoch=7 batch=200 loss=0.023256070911884308\n",
      "Epoch=7 batch=300 loss=0.027225475758314133\n",
      "Epoch=7 batch=400 loss=0.023204229772090912\n",
      "Epoch=8 batch=100 loss=0.021271003410220146\n",
      "Epoch=8 batch=200 loss=0.022213485091924667\n",
      "Epoch=8 batch=300 loss=0.02277347445487976\n",
      "Epoch=8 batch=400 loss=0.023589493706822395\n",
      "Epoch=9 batch=100 loss=0.023834994062781334\n",
      "Epoch=9 batch=200 loss=0.02548244781792164\n",
      "Epoch=9 batch=300 loss=0.023945974186062813\n",
      "Epoch=9 batch=400 loss=0.02340763248503208\n",
      "Epoch=10 batch=100 loss=0.024265922605991364\n",
      "Epoch=10 batch=200 loss=0.0235698614269495\n",
      "Epoch=10 batch=300 loss=0.03075556829571724\n",
      "Epoch=10 batch=400 loss=0.0227292999625206\n"
     ]
    }
   ],
   "source": [
    "#迭代训练10轮\n",
    "for epoch in range(10):\n",
    "    for i, data in enumerate(train_loader):\n",
    "        inputs, labels = data             \n",
    "        inputs, labels = inputs.to(device), labels.to(device)\n",
    "        \n",
    "        #增加噪声\n",
    "        inputs_noise=inputs+0.1*torch.randn(inputs.shape).to(device)\n",
    "        inputs_noise=torch.clamp(inputs_noise,0.0,1.0)\n",
    "        \n",
    "        optimizer.zero_grad() \n",
    "        output = autoencoder(inputs_noise)\n",
    "        loss = loss_func(output, inputs)                    \n",
    "        loss.backward()                     \n",
    "        optimizer.step()                  \n",
    "\n",
    "        if (i % 100 == 0) and ( i > 0 ):\n",
    "            print(\"Epoch={} batch={} loss={}\".format(epoch+1, i, loss.data.cpu().numpy()))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 验证自编码器去噪对模型识别的影响"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:22:22.806514Z",
     "start_time": "2019-12-02T13:22:22.799528Z"
    }
   },
   "outputs": [],
   "source": [
    "TOTAL_NUM = 1000\n",
    "pretrained_model=\"model/mnist_model_dict.pth\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:22:23.220894Z",
     "start_time": "2019-12-02T13:22:23.202166Z"
    }
   },
   "outputs": [],
   "source": [
    "#使用MNIST测试数据集 随机挑选TOTAL_NUM个\n",
    "# Pytorch下的MNIST数据集默认就是归一化了\n",
    "test_loader = torch.utils.data.DataLoader(\n",
    "    datasets.MNIST('/home/shenchenkai/data/mnist_pytorch/', train=False, download=False, transform=transforms.Compose([\n",
    "        transforms.ToTensor(),\n",
    "    ])),\n",
    "    batch_size=1, shuffle=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:22:23.831147Z",
     "start_time": "2019-12-02T13:22:23.795700Z"
    }
   },
   "outputs": [],
   "source": [
    "# Define what device we are using\n",
    "logging.info(\"CUDA Available: {}\".format(torch.cuda.is_available()))\n",
    "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
    "\n",
    "# Initialize the network\n",
    "model = Net().to(device)\n",
    "# Load the pretrained model\n",
    "model.load_state_dict(torch.load(pretrained_model, map_location='cpu'))\n",
    "# Set the model in evaluation mode. In this case this is for the Dropout layers\n",
    "model.eval()\n",
    "# use test data to generate adversarial examples\n",
    "total_count = 0\n",
    "#去噪前正确识别个数\n",
    "pre_count=0\n",
    "#去噪后正确识别个数\n",
    "decoded_count = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:22:27.096688Z",
     "start_time": "2019-12-02T13:22:24.607619Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[TEST_DATASET]: pre_count=980, total_count=1000, pre_count_rate=0.980000  decoded_count=956 decoded_count_rate=0.956000\n"
     ]
    }
   ],
   "source": [
    "for i, data in enumerate(test_loader):\n",
    "    inputs, labels = data\n",
    "    inputs, labels = inputs.to(device), labels.to(device)\n",
    "    total_count += 1\n",
    "\n",
    "    #去噪前\n",
    "    pre_label = np.argmax(model(inputs).data.cpu().numpy())\n",
    "    if pre_label == labels[0]:\n",
    "        pre_count += 1\n",
    "\n",
    "    #使用自编码器去噪\n",
    "    output = autoencoder(inputs)\n",
    "    output = output.view(1, 1, 28, 28)\n",
    "    decoded_label = np.argmax(model(output).data.cpu().numpy())\n",
    "    if decoded_label == labels[0]:\n",
    "        decoded_count += 1\n",
    "\n",
    "    if total_count >= TOTAL_NUM:\n",
    "        print(\n",
    "            \"[TEST_DATASET]: pre_count=%d, total_count=%d, pre_count_rate=%f  decoded_count=%d decoded_count_rate=%f\"\n",
    "            % (pre_count, total_count, float(pre_count) / total_count,\n",
    "               decoded_count, float(decoded_count) / total_count))\n",
    "        break"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用自编码器过滤噪音"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:22:31.790545Z",
     "start_time": "2019-12-02T13:22:31.785455Z"
    }
   },
   "outputs": [],
   "source": [
    "TOTAL_NUM = 1000\n",
    "pretrained_model=\"model/mnist_model_dict.pth\"\n",
    "loss_func = torch.nn.CrossEntropyLoss()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:22:32.652050Z",
     "start_time": "2019-12-02T13:22:32.608639Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cuda\n"
     ]
    }
   ],
   "source": [
    "#使用MNIST测试数据集 随机挑选TOTAL_NUM个\n",
    "# Pytorch下的MNIST数据集默认就是归一化了\n",
    "test_loader = torch.utils.data.DataLoader(\n",
    "    datasets.MNIST('/home/shenchenkai/data/mnist_pytorch/', train=False, download=False, transform=transforms.Compose([\n",
    "        transforms.ToTensor(),\n",
    "    ])),\n",
    "    batch_size=1, shuffle=True)\n",
    "\n",
    "# Define what device we are using\n",
    "logging.info(\"CUDA Available: {}\".format(torch.cuda.is_available()))\n",
    "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
    "\n",
    "# Initialize the network\n",
    "model = Net().to(device)\n",
    "# Load the pretrained model\n",
    "model.load_state_dict(torch.load(pretrained_model, map_location='cpu'))\n",
    "# Set the model in evaluation mode. In this case this is for the Dropout layers\n",
    "model.eval()\n",
    "# advbox demo\n",
    "m = PytorchModel(model, loss_func,(0, 1), channel_axis=1)\n",
    "#实例化FGSM\n",
    "attack = FGSM(m)\n",
    "#设置攻击步长为0.1\n",
    "attack_config = {\"epsilons\": 0.01}\n",
    "\n",
    "# use test data to generate adversarial examples\n",
    "total_count = 0\n",
    "# 去噪前的攻击成功个数\n",
    "fooling_count = 0\n",
    "# 去噪后的攻击成功个数\n",
    "decoded_fooling_count = 0\n",
    "#记录原始数据经过自编码器去噪后可以正常识别的个数\n",
    "decoded_count = 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-12-02T13:23:28.206097Z",
     "start_time": "2019-12-02T13:22:33.356283Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "attack success, original_label=7, adversarial_label=9, count=1\n",
      "attack success, original_label=2, adversarial_label=3, count=2\n",
      "attack success, original_label=5, adversarial_label=6, count=3\n",
      "attack success, original_label=9, adversarial_label=4, count=4\n",
      "attack success, original_label=9, adversarial_label=4, count=5\n",
      "attack success, original_label=2, adversarial_label=8, count=6\n",
      "attack success, original_label=6, adversarial_label=4, count=7\n",
      "attack success, original_label=2, adversarial_label=7, count=8\n",
      "orig_label=2 adv_label=7 decoded_label=7\n",
      "attack success, original_label=0, adversarial_label=6, count=9\n",
      "attack success, original_label=1, adversarial_label=3, count=10\n",
      "attack success, original_label=4, adversarial_label=9, count=11\n",
      "attack success, original_label=2, adversarial_label=3, count=12\n",
      "attack success, original_label=9, adversarial_label=7, count=13\n",
      "attack success, original_label=2, adversarial_label=1, count=14\n",
      "attack success, original_label=3, adversarial_label=6, count=15\n",
      "attack success, original_label=5, adversarial_label=8, count=16\n",
      "attack success, original_label=1, adversarial_label=8, count=17\n",
      "attack success, original_label=6, adversarial_label=4, count=18\n",
      "attack success, original_label=6, adversarial_label=0, count=19\n",
      "attack success, original_label=2, adversarial_label=3, count=20\n",
      "attack success, original_label=3, adversarial_label=8, count=21\n",
      "attack success, original_label=9, adversarial_label=4, count=22\n",
      "orig_label=9 adv_label=4 decoded_label=4\n",
      "attack success, original_label=5, adversarial_label=8, count=23\n",
      "attack success, original_label=6, adversarial_label=2, count=24\n",
      "attack success, original_label=4, adversarial_label=8, count=25\n",
      "attack success, original_label=6, adversarial_label=8, count=26\n",
      "attack success, original_label=2, adversarial_label=8, count=27\n",
      "attack success, original_label=3, adversarial_label=8, count=28\n",
      "attack success, original_label=0, adversarial_label=6, count=29\n",
      "attack success, original_label=6, adversarial_label=8, count=30\n",
      "attack success, original_label=2, adversarial_label=3, count=31\n",
      "attack success, original_label=1, adversarial_label=8, count=32\n",
      "attack success, original_label=9, adversarial_label=4, count=33\n",
      "orig_label=9 adv_label=4 decoded_label=4\n",
      "attack success, original_label=0, adversarial_label=8, count=34\n",
      "attack success, original_label=9, adversarial_label=4, count=35\n",
      "attack success, original_label=4, adversarial_label=9, count=36\n",
      "attack success, original_label=4, adversarial_label=9, count=37\n",
      "attack success, original_label=4, adversarial_label=0, count=38\n",
      "attack success, original_label=3, adversarial_label=5, count=39\n",
      "attack success, original_label=6, adversarial_label=0, count=40\n",
      "attack success, original_label=7, adversarial_label=9, count=41\n",
      "attack success, original_label=1, adversarial_label=8, count=42\n",
      "attack success, original_label=9, adversarial_label=5, count=43\n",
      "attack success, original_label=1, adversarial_label=8, count=44\n",
      "attack success, original_label=4, adversarial_label=8, count=45\n",
      "attack success, original_label=0, adversarial_label=6, count=46\n",
      "attack success, original_label=7, adversarial_label=3, count=47\n",
      "attack success, original_label=6, adversarial_label=8, count=48\n",
      "attack success, original_label=0, adversarial_label=9, count=49\n",
      "attack success, original_label=0, adversarial_label=9, count=50\n",
      "attack success, original_label=5, adversarial_label=0, count=51\n",
      "orig_label=5 adv_label=0 decoded_label=0\n",
      "attack success, original_label=2, adversarial_label=3, count=52\n",
      "attack success, original_label=5, adversarial_label=6, count=53\n",
      "attack success, original_label=7, adversarial_label=3, count=54\n",
      "attack success, original_label=5, adversarial_label=6, count=55\n",
      "attack success, original_label=9, adversarial_label=8, count=56\n",
      "attack success, original_label=3, adversarial_label=5, count=57\n",
      "orig_label=3 adv_label=5 decoded_label=5\n",
      "attack success, original_label=8, adversarial_label=9, count=58\n",
      "attack success, original_label=4, adversarial_label=8, count=59\n",
      "attack success, original_label=1, adversarial_label=8, count=60\n",
      "attack success, original_label=1, adversarial_label=8, count=61\n",
      "attack success, original_label=5, adversarial_label=6, count=62\n",
      "attack success, original_label=0, adversarial_label=6, count=63\n",
      "attack success, original_label=5, adversarial_label=9, count=64\n",
      "attack success, original_label=0, adversarial_label=4, count=65\n",
      "attack success, original_label=1, adversarial_label=8, count=66\n",
      "attack success, original_label=9, adversarial_label=4, count=67\n",
      "attack success, original_label=6, adversarial_label=8, count=68\n",
      "attack success, original_label=5, adversarial_label=8, count=69\n",
      "attack success, original_label=3, adversarial_label=8, count=70\n",
      "attack success, original_label=8, adversarial_label=3, count=71\n",
      "attack success, original_label=9, adversarial_label=4, count=72\n",
      "attack success, original_label=0, adversarial_label=8, count=73\n",
      "attack success, original_label=7, adversarial_label=9, count=74\n",
      "orig_label=7 adv_label=9 decoded_label=9\n",
      "attack success, original_label=6, adversarial_label=0, count=75\n",
      "attack success, original_label=8, adversarial_label=3, count=76\n",
      "attack success, original_label=6, adversarial_label=4, count=77\n",
      "attack success, original_label=9, adversarial_label=4, count=78\n",
      "attack success, original_label=3, adversarial_label=8, count=79\n",
      "attack success, original_label=2, adversarial_label=3, count=80\n",
      "attack success, original_label=8, adversarial_label=5, count=81\n",
      "attack success, original_label=3, adversarial_label=5, count=82\n",
      "attack success, original_label=8, adversarial_label=5, count=83\n",
      "attack success, original_label=5, adversarial_label=9, count=84\n",
      "attack success, original_label=0, adversarial_label=6, count=85\n",
      "attack success, original_label=9, adversarial_label=4, count=86\n",
      "attack success, original_label=7, adversarial_label=9, count=87\n",
      "attack success, original_label=2, adversarial_label=3, count=88\n",
      "attack success, original_label=4, adversarial_label=8, count=89\n",
      "attack success, original_label=8, adversarial_label=5, count=90\n",
      "attack success, original_label=4, adversarial_label=7, count=91\n",
      "attack success, original_label=8, adversarial_label=9, count=92\n",
      "attack success, original_label=9, adversarial_label=4, count=93\n",
      "attack success, original_label=8, adversarial_label=3, count=94\n",
      "attack success, original_label=0, adversarial_label=6, count=95\n",
      "attack success, original_label=6, adversarial_label=8, count=96\n",
      "attack success, original_label=2, adversarial_label=3, count=97\n",
      "attack success, original_label=0, adversarial_label=6, count=98\n",
      "attack success, original_label=7, adversarial_label=9, count=99\n",
      "attack success, original_label=8, adversarial_label=5, count=100\n",
      "attack success, original_label=4, adversarial_label=8, count=101\n",
      "attack success, original_label=1, adversarial_label=8, count=102\n",
      "attack success, original_label=7, adversarial_label=9, count=103\n",
      "attack success, original_label=6, adversarial_label=8, count=104\n",
      "attack success, original_label=4, adversarial_label=8, count=105\n",
      "attack success, original_label=4, adversarial_label=8, count=106\n",
      "attack success, original_label=2, adversarial_label=6, count=107\n",
      "attack success, original_label=6, adversarial_label=4, count=108\n",
      "attack success, original_label=1, adversarial_label=8, count=109\n",
      "attack success, original_label=6, adversarial_label=4, count=110\n",
      "attack success, original_label=6, adversarial_label=4, count=111\n",
      "attack success, original_label=8, adversarial_label=3, count=112\n",
      "orig_label=8 adv_label=3 decoded_label=3\n",
      "attack success, original_label=7, adversarial_label=4, count=113\n",
      "attack success, original_label=4, adversarial_label=8, count=114\n",
      "attack success, original_label=6, adversarial_label=4, count=115\n",
      "attack success, original_label=6, adversarial_label=4, count=116\n",
      "attack success, original_label=4, adversarial_label=8, count=117\n",
      "attack success, original_label=6, adversarial_label=4, count=118\n",
      "attack success, original_label=8, adversarial_label=6, count=119\n",
      "attack success, original_label=7, adversarial_label=4, count=120\n",
      "attack success, original_label=3, adversarial_label=9, count=121\n",
      "attack success, original_label=1, adversarial_label=8, count=122\n",
      "attack success, original_label=0, adversarial_label=9, count=123\n",
      "attack success, original_label=6, adversarial_label=4, count=124\n",
      "attack success, original_label=1, adversarial_label=8, count=125\n",
      "attack success, original_label=6, adversarial_label=4, count=126\n",
      "attack success, original_label=8, adversarial_label=5, count=127\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "attack success, original_label=0, adversarial_label=2, count=128\n",
      "attack success, original_label=1, adversarial_label=8, count=129\n",
      "attack success, original_label=7, adversarial_label=3, count=130\n",
      "attack success, original_label=8, adversarial_label=6, count=131\n",
      "attack success, original_label=9, adversarial_label=4, count=132\n",
      "attack success, original_label=9, adversarial_label=7, count=133\n",
      "attack success, original_label=8, adversarial_label=2, count=134\n",
      "attack success, original_label=0, adversarial_label=9, count=135\n",
      "attack success, original_label=7, adversarial_label=9, count=136\n",
      "attack success, original_label=9, adversarial_label=8, count=137\n",
      "attack success, original_label=4, adversarial_label=0, count=138\n",
      "attack success, original_label=7, adversarial_label=9, count=139\n",
      "attack success, original_label=6, adversarial_label=8, count=140\n",
      "attack success, original_label=4, adversarial_label=9, count=141\n",
      "attack success, original_label=7, adversarial_label=9, count=142\n",
      "attack success, original_label=6, adversarial_label=8, count=143\n",
      "attack success, original_label=2, adversarial_label=8, count=144\n",
      "attack success, original_label=1, adversarial_label=8, count=145\n",
      "attack success, original_label=6, adversarial_label=8, count=146\n",
      "attack success, original_label=8, adversarial_label=0, count=147\n",
      "attack success, original_label=8, adversarial_label=0, count=148\n",
      "attack success, original_label=6, adversarial_label=4, count=149\n",
      "attack success, original_label=0, adversarial_label=8, count=150\n",
      "attack success, original_label=7, adversarial_label=3, count=151\n",
      "attack success, original_label=5, adversarial_label=9, count=152\n",
      "attack success, original_label=9, adversarial_label=8, count=153\n",
      "attack success, original_label=0, adversarial_label=9, count=154\n",
      "attack success, original_label=5, adversarial_label=8, count=155\n",
      "attack success, original_label=4, adversarial_label=9, count=156\n",
      "attack success, original_label=2, adversarial_label=8, count=157\n",
      "attack success, original_label=7, adversarial_label=3, count=158\n",
      "attack success, original_label=2, adversarial_label=0, count=159\n",
      "attack success, original_label=8, adversarial_label=9, count=160\n",
      "attack success, original_label=5, adversarial_label=3, count=161\n",
      "attack success, original_label=5, adversarial_label=3, count=162\n",
      "attack success, original_label=4, adversarial_label=0, count=163\n",
      "attack success, original_label=5, adversarial_label=3, count=164\n",
      "attack success, original_label=5, adversarial_label=6, count=165\n",
      "attack success, original_label=4, adversarial_label=8, count=166\n",
      "orig_label=4 adv_label=8 decoded_label=9\n",
      "attack success, original_label=1, adversarial_label=8, count=167\n",
      "attack success, original_label=8, adversarial_label=9, count=168\n",
      "attack success, original_label=8, adversarial_label=0, count=169\n",
      "attack success, original_label=9, adversarial_label=5, count=170\n",
      "attack success, original_label=8, adversarial_label=5, count=171\n",
      "attack success, original_label=3, adversarial_label=9, count=172\n",
      "attack success, original_label=2, adversarial_label=3, count=173\n",
      "orig_label=2 adv_label=3 decoded_label=3\n",
      "attack success, original_label=6, adversarial_label=4, count=174\n",
      "attack success, original_label=4, adversarial_label=9, count=175\n",
      "attack success, original_label=8, adversarial_label=3, count=176\n",
      "attack success, original_label=1, adversarial_label=8, count=177\n",
      "attack success, original_label=2, adversarial_label=3, count=178\n",
      "attack success, original_label=7, adversarial_label=9, count=179\n",
      "attack success, original_label=4, adversarial_label=8, count=180\n",
      "attack success, original_label=6, adversarial_label=8, count=181\n",
      "attack success, original_label=4, adversarial_label=9, count=182\n",
      "attack success, original_label=9, adversarial_label=4, count=183\n",
      "attack success, original_label=4, adversarial_label=8, count=184\n",
      "attack success, original_label=6, adversarial_label=8, count=185\n",
      "attack success, original_label=9, adversarial_label=4, count=186\n",
      "orig_label=9 adv_label=4 decoded_label=4\n",
      "attack success, original_label=1, adversarial_label=8, count=187\n",
      "attack success, original_label=6, adversarial_label=8, count=188\n",
      "attack success, original_label=4, adversarial_label=7, count=189\n",
      "attack success, original_label=5, adversarial_label=8, count=190\n",
      "attack success, original_label=1, adversarial_label=8, count=191\n",
      "attack success, original_label=0, adversarial_label=7, count=192\n",
      "attack success, original_label=0, adversarial_label=8, count=193\n",
      "attack success, original_label=8, adversarial_label=5, count=194\n",
      "attack success, original_label=7, adversarial_label=9, count=195\n",
      "attack success, original_label=9, adversarial_label=4, count=196\n",
      "attack success, original_label=5, adversarial_label=6, count=197\n",
      "attack success, original_label=0, adversarial_label=8, count=198\n",
      "attack success, original_label=2, adversarial_label=8, count=199\n",
      "attack success, original_label=2, adversarial_label=8, count=200\n",
      "attack success, original_label=2, adversarial_label=1, count=201\n",
      "attack success, original_label=0, adversarial_label=6, count=202\n",
      "attack success, original_label=6, adversarial_label=4, count=203\n",
      "attack success, original_label=7, adversarial_label=4, count=204\n",
      "orig_label=7 adv_label=4 decoded_label=1\n",
      "attack success, original_label=0, adversarial_label=6, count=205\n",
      "attack success, original_label=7, adversarial_label=8, count=206\n",
      "attack success, original_label=8, adversarial_label=6, count=207\n",
      "attack success, original_label=5, adversarial_label=6, count=208\n",
      "attack success, original_label=9, adversarial_label=4, count=209\n",
      "attack success, original_label=7, adversarial_label=3, count=210\n",
      "attack success, original_label=1, adversarial_label=8, count=211\n",
      "attack success, original_label=0, adversarial_label=9, count=212\n",
      "attack success, original_label=8, adversarial_label=5, count=213\n",
      "attack success, original_label=4, adversarial_label=9, count=214\n",
      "attack success, original_label=8, adversarial_label=3, count=215\n",
      "attack success, original_label=2, adversarial_label=3, count=216\n",
      "attack success, original_label=9, adversarial_label=4, count=217\n",
      "attack success, original_label=4, adversarial_label=8, count=218\n",
      "attack success, original_label=8, adversarial_label=0, count=219\n",
      "attack success, original_label=1, adversarial_label=6, count=220\n",
      "attack success, original_label=1, adversarial_label=8, count=221\n",
      "attack success, original_label=9, adversarial_label=8, count=222\n",
      "attack success, original_label=6, adversarial_label=5, count=223\n",
      "attack success, original_label=4, adversarial_label=9, count=224\n",
      "attack success, original_label=2, adversarial_label=8, count=225\n",
      "attack success, original_label=4, adversarial_label=9, count=226\n",
      "attack success, original_label=2, adversarial_label=8, count=227\n",
      "attack success, original_label=8, adversarial_label=3, count=228\n",
      "attack success, original_label=0, adversarial_label=9, count=229\n",
      "attack success, original_label=3, adversarial_label=6, count=230\n",
      "attack success, original_label=3, adversarial_label=5, count=231\n",
      "orig_label=3 adv_label=5 decoded_label=5\n",
      "attack success, original_label=2, adversarial_label=1, count=232\n",
      "attack success, original_label=3, adversarial_label=8, count=233\n",
      "attack success, original_label=8, adversarial_label=9, count=234\n",
      "attack success, original_label=3, adversarial_label=5, count=235\n",
      "attack success, original_label=1, adversarial_label=8, count=236\n",
      "attack success, original_label=6, adversarial_label=5, count=237\n",
      "attack success, original_label=2, adversarial_label=3, count=238\n",
      "attack success, original_label=2, adversarial_label=8, count=239\n",
      "attack success, original_label=6, adversarial_label=5, count=240\n",
      "attack success, original_label=7, adversarial_label=3, count=241\n",
      "attack success, original_label=5, adversarial_label=6, count=242\n",
      "attack success, original_label=8, adversarial_label=3, count=243\n",
      "attack success, original_label=5, adversarial_label=6, count=244\n",
      "attack success, original_label=3, adversarial_label=8, count=245\n",
      "orig_label=3 adv_label=8 decoded_label=8\n",
      "attack success, original_label=1, adversarial_label=8, count=246\n",
      "attack success, original_label=0, adversarial_label=6, count=247\n",
      "attack success, original_label=0, adversarial_label=9, count=248\n",
      "attack success, original_label=1, adversarial_label=8, count=249\n",
      "attack success, original_label=9, adversarial_label=4, count=250\n",
      "attack success, original_label=4, adversarial_label=8, count=251\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "attack success, original_label=0, adversarial_label=9, count=252\n",
      "attack success, original_label=2, adversarial_label=3, count=253\n",
      "attack success, original_label=6, adversarial_label=8, count=254\n",
      "attack success, original_label=3, adversarial_label=9, count=255\n",
      "attack success, original_label=2, adversarial_label=8, count=256\n",
      "attack success, original_label=4, adversarial_label=9, count=257\n",
      "attack success, original_label=5, adversarial_label=6, count=258\n",
      "attack success, original_label=0, adversarial_label=6, count=259\n",
      "attack success, original_label=6, adversarial_label=0, count=260\n",
      "attack success, original_label=6, adversarial_label=4, count=261\n",
      "attack success, original_label=8, adversarial_label=6, count=262\n",
      "attack success, original_label=2, adversarial_label=1, count=263\n",
      "attack success, original_label=0, adversarial_label=9, count=264\n",
      "attack success, original_label=9, adversarial_label=8, count=265\n",
      "attack success, original_label=1, adversarial_label=8, count=266\n",
      "attack success, original_label=0, adversarial_label=6, count=267\n",
      "attack success, original_label=0, adversarial_label=9, count=268\n",
      "attack success, original_label=5, adversarial_label=8, count=269\n",
      "attack success, original_label=9, adversarial_label=4, count=270\n",
      "attack success, original_label=2, adversarial_label=8, count=271\n",
      "attack success, original_label=8, adversarial_label=9, count=272\n",
      "attack success, original_label=6, adversarial_label=9, count=273\n",
      "attack success, original_label=1, adversarial_label=8, count=274\n",
      "attack success, original_label=5, adversarial_label=9, count=275\n",
      "attack success, original_label=0, adversarial_label=6, count=276\n",
      "attack success, original_label=6, adversarial_label=8, count=277\n",
      "attack success, original_label=5, adversarial_label=9, count=278\n",
      "attack success, original_label=9, adversarial_label=4, count=279\n",
      "attack success, original_label=2, adversarial_label=0, count=280\n",
      "attack success, original_label=1, adversarial_label=8, count=281\n",
      "attack success, original_label=9, adversarial_label=7, count=282\n",
      "attack success, original_label=3, adversarial_label=9, count=283\n",
      "attack success, original_label=3, adversarial_label=8, count=284\n",
      "attack success, original_label=2, adversarial_label=4, count=285\n",
      "orig_label=2 adv_label=4 decoded_label=4\n",
      "attack success, original_label=1, adversarial_label=4, count=286\n",
      "attack success, original_label=4, adversarial_label=8, count=287\n",
      "attack success, original_label=4, adversarial_label=8, count=288\n",
      "attack success, original_label=4, adversarial_label=8, count=289\n",
      "attack success, original_label=5, adversarial_label=8, count=290\n",
      "attack success, original_label=8, adversarial_label=9, count=291\n",
      "attack success, original_label=0, adversarial_label=6, count=292\n",
      "attack success, original_label=2, adversarial_label=8, count=293\n",
      "attack success, original_label=7, adversarial_label=9, count=294\n",
      "attack success, original_label=7, adversarial_label=9, count=295\n",
      "attack success, original_label=0, adversarial_label=5, count=296\n",
      "attack success, original_label=2, adversarial_label=1, count=297\n",
      "attack success, original_label=2, adversarial_label=3, count=298\n",
      "attack success, original_label=5, adversarial_label=8, count=299\n",
      "attack success, original_label=3, adversarial_label=9, count=300\n",
      "attack success, original_label=0, adversarial_label=9, count=301\n",
      "attack success, original_label=7, adversarial_label=8, count=302\n",
      "orig_label=7 adv_label=8 decoded_label=1\n",
      "attack success, original_label=9, adversarial_label=8, count=303\n",
      "attack success, original_label=6, adversarial_label=4, count=304\n",
      "attack success, original_label=3, adversarial_label=5, count=305\n",
      "attack success, original_label=5, adversarial_label=9, count=306\n",
      "attack success, original_label=8, adversarial_label=6, count=307\n",
      "attack success, original_label=5, adversarial_label=8, count=308\n",
      "attack success, original_label=5, adversarial_label=3, count=309\n",
      "attack success, original_label=7, adversarial_label=9, count=310\n",
      "orig_label=7 adv_label=9 decoded_label=9\n",
      "attack success, original_label=6, adversarial_label=4, count=311\n",
      "attack success, original_label=9, adversarial_label=8, count=312\n",
      "attack success, original_label=6, adversarial_label=4, count=313\n",
      "attack success, original_label=7, adversarial_label=9, count=314\n",
      "attack success, original_label=2, adversarial_label=8, count=315\n",
      "attack success, original_label=6, adversarial_label=4, count=316\n",
      "attack success, original_label=1, adversarial_label=8, count=317\n",
      "attack success, original_label=0, adversarial_label=5, count=318\n",
      "attack success, original_label=8, adversarial_label=3, count=319\n",
      "attack success, original_label=2, adversarial_label=1, count=320\n",
      "attack success, original_label=3, adversarial_label=8, count=321\n",
      "attack success, original_label=7, adversarial_label=9, count=322\n",
      "attack success, original_label=7, adversarial_label=3, count=323\n",
      "attack success, original_label=5, adversarial_label=9, count=324\n",
      "attack success, original_label=2, adversarial_label=4, count=325\n",
      "attack success, original_label=6, adversarial_label=4, count=326\n",
      "attack success, original_label=8, adversarial_label=5, count=327\n",
      "attack success, original_label=0, adversarial_label=6, count=328\n",
      "attack success, original_label=2, adversarial_label=3, count=329\n",
      "attack success, original_label=4, adversarial_label=8, count=330\n",
      "attack success, original_label=4, adversarial_label=8, count=331\n",
      "attack success, original_label=8, adversarial_label=3, count=332\n",
      "orig_label=8 adv_label=3 decoded_label=3\n",
      "attack success, original_label=9, adversarial_label=4, count=333\n",
      "attack success, original_label=5, adversarial_label=9, count=334\n",
      "attack success, original_label=8, adversarial_label=3, count=335\n",
      "attack success, original_label=1, adversarial_label=8, count=336\n",
      "attack success, original_label=3, adversarial_label=8, count=337\n",
      "attack success, original_label=1, adversarial_label=8, count=338\n",
      "attack success, original_label=3, adversarial_label=9, count=339\n",
      "attack success, original_label=6, adversarial_label=8, count=340\n",
      "attack success, original_label=7, adversarial_label=3, count=341\n",
      "attack success, original_label=0, adversarial_label=9, count=342\n",
      "attack success, original_label=8, adversarial_label=3, count=343\n",
      "orig_label=8 adv_label=3 decoded_label=3\n",
      "attack success, original_label=7, adversarial_label=9, count=344\n",
      "attack success, original_label=4, adversarial_label=9, count=345\n",
      "attack success, original_label=4, adversarial_label=9, count=346\n",
      "attack success, original_label=6, adversarial_label=4, count=347\n",
      "attack success, original_label=3, adversarial_label=8, count=348\n",
      "attack success, original_label=2, adversarial_label=9, count=349\n",
      "attack success, original_label=1, adversarial_label=8, count=350\n",
      "attack success, original_label=2, adversarial_label=3, count=351\n",
      "attack success, original_label=7, adversarial_label=9, count=352\n",
      "attack success, original_label=6, adversarial_label=0, count=353\n",
      "attack success, original_label=1, adversarial_label=8, count=354\n",
      "attack success, original_label=7, adversarial_label=8, count=355\n",
      "attack success, original_label=8, adversarial_label=9, count=356\n",
      "attack success, original_label=9, adversarial_label=8, count=357\n",
      "attack success, original_label=6, adversarial_label=8, count=358\n",
      "attack success, original_label=0, adversarial_label=9, count=359\n",
      "attack success, original_label=2, adversarial_label=0, count=360\n",
      "attack success, original_label=1, adversarial_label=8, count=361\n",
      "attack success, original_label=8, adversarial_label=0, count=362\n",
      "attack success, original_label=6, adversarial_label=4, count=363\n",
      "attack success, original_label=9, adversarial_label=4, count=364\n",
      "attack success, original_label=2, adversarial_label=3, count=365\n",
      "attack success, original_label=2, adversarial_label=3, count=366\n",
      "attack success, original_label=3, adversarial_label=9, count=367\n",
      "attack success, original_label=8, adversarial_label=5, count=368\n",
      "attack success, original_label=5, adversarial_label=3, count=369\n",
      "attack success, original_label=4, adversarial_label=8, count=370\n",
      "attack success, original_label=1, adversarial_label=8, count=371\n",
      "attack success, original_label=8, adversarial_label=5, count=372\n",
      "attack success, original_label=6, adversarial_label=9, count=373\n",
      "attack success, original_label=4, adversarial_label=8, count=374\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "attack success, original_label=0, adversarial_label=9, count=375\n",
      "attack success, original_label=7, adversarial_label=9, count=376\n",
      "attack success, original_label=0, adversarial_label=9, count=377\n",
      "attack success, original_label=5, adversarial_label=8, count=378\n",
      "attack success, original_label=1, adversarial_label=8, count=379\n",
      "attack success, original_label=3, adversarial_label=9, count=380\n",
      "attack success, original_label=9, adversarial_label=8, count=381\n",
      "attack success, original_label=9, adversarial_label=4, count=382\n",
      "attack success, original_label=6, adversarial_label=0, count=383\n",
      "attack success, original_label=3, adversarial_label=5, count=384\n",
      "attack success, original_label=0, adversarial_label=6, count=385\n",
      "attack success, original_label=5, adversarial_label=9, count=386\n",
      "attack success, original_label=4, adversarial_label=8, count=387\n",
      "orig_label=4 adv_label=8 decoded_label=8\n",
      "attack success, original_label=4, adversarial_label=8, count=388\n",
      "attack success, original_label=8, adversarial_label=9, count=389\n",
      "attack success, original_label=8, adversarial_label=2, count=390\n",
      "attack success, original_label=6, adversarial_label=5, count=391\n",
      "attack success, original_label=0, adversarial_label=8, count=392\n",
      "attack success, original_label=6, adversarial_label=4, count=393\n",
      "attack success, original_label=6, adversarial_label=5, count=394\n",
      "attack success, original_label=8, adversarial_label=3, count=395\n",
      "attack success, original_label=4, adversarial_label=8, count=396\n",
      "attack success, original_label=9, adversarial_label=4, count=397\n",
      "attack success, original_label=1, adversarial_label=8, count=398\n",
      "attack success, original_label=0, adversarial_label=8, count=399\n",
      "attack success, original_label=7, adversarial_label=9, count=400\n",
      "attack success, original_label=4, adversarial_label=8, count=401\n",
      "attack success, original_label=8, adversarial_label=3, count=402\n",
      "attack success, original_label=1, adversarial_label=8, count=403\n",
      "attack success, original_label=7, adversarial_label=9, count=404\n",
      "attack success, original_label=3, adversarial_label=9, count=405\n",
      "attack success, original_label=0, adversarial_label=9, count=406\n",
      "attack success, original_label=5, adversarial_label=3, count=407\n",
      "attack success, original_label=9, adversarial_label=8, count=408\n",
      "attack success, original_label=2, adversarial_label=3, count=409\n",
      "attack success, original_label=7, adversarial_label=3, count=410\n",
      "attack success, original_label=0, adversarial_label=6, count=411\n",
      "attack success, original_label=2, adversarial_label=8, count=412\n",
      "attack success, original_label=4, adversarial_label=7, count=413\n",
      "attack success, original_label=1, adversarial_label=8, count=414\n",
      "attack success, original_label=8, adversarial_label=0, count=415\n",
      "attack success, original_label=2, adversarial_label=8, count=416\n",
      "attack success, original_label=2, adversarial_label=4, count=417\n",
      "orig_label=2 adv_label=4 decoded_label=4\n",
      "attack success, original_label=4, adversarial_label=8, count=418\n",
      "attack success, original_label=4, adversarial_label=8, count=419\n",
      "attack success, original_label=3, adversarial_label=8, count=420\n",
      "attack success, original_label=8, adversarial_label=3, count=421\n",
      "attack success, original_label=7, adversarial_label=9, count=422\n",
      "attack success, original_label=4, adversarial_label=0, count=423\n",
      "attack success, original_label=7, adversarial_label=3, count=424\n",
      "attack success, original_label=8, adversarial_label=3, count=425\n",
      "attack success, original_label=3, adversarial_label=8, count=426\n",
      "attack success, original_label=3, adversarial_label=5, count=427\n",
      "attack success, original_label=3, adversarial_label=9, count=428\n",
      "attack success, original_label=9, adversarial_label=4, count=429\n",
      "attack success, original_label=9, adversarial_label=4, count=430\n",
      "attack success, original_label=5, adversarial_label=8, count=431\n",
      "attack success, original_label=9, adversarial_label=4, count=432\n",
      "attack success, original_label=6, adversarial_label=5, count=433\n",
      "attack success, original_label=8, adversarial_label=5, count=434\n",
      "attack success, original_label=2, adversarial_label=0, count=435\n",
      "attack success, original_label=2, adversarial_label=3, count=436\n",
      "attack success, original_label=5, adversarial_label=8, count=437\n",
      "attack success, original_label=8, adversarial_label=0, count=438\n",
      "orig_label=8 adv_label=0 decoded_label=0\n",
      "attack success, original_label=7, adversarial_label=3, count=439\n",
      "attack success, original_label=5, adversarial_label=6, count=440\n",
      "attack success, original_label=7, adversarial_label=9, count=441\n",
      "attack success, original_label=7, adversarial_label=8, count=442\n",
      "attack success, original_label=3, adversarial_label=8, count=443\n",
      "attack success, original_label=4, adversarial_label=8, count=444\n",
      "attack success, original_label=2, adversarial_label=8, count=445\n",
      "attack success, original_label=3, adversarial_label=1, count=446\n",
      "attack success, original_label=4, adversarial_label=8, count=447\n",
      "attack success, original_label=0, adversarial_label=6, count=448\n",
      "attack success, original_label=2, adversarial_label=8, count=449\n",
      "attack success, original_label=9, adversarial_label=4, count=450\n",
      "attack success, original_label=7, adversarial_label=3, count=451\n",
      "attack success, original_label=6, adversarial_label=0, count=452\n",
      "attack success, original_label=8, adversarial_label=9, count=453\n",
      "attack success, original_label=2, adversarial_label=3, count=454\n",
      "attack success, original_label=2, adversarial_label=8, count=455\n",
      "attack success, original_label=4, adversarial_label=8, count=456\n",
      "attack success, original_label=6, adversarial_label=5, count=457\n",
      "attack success, original_label=3, adversarial_label=5, count=458\n",
      "attack success, original_label=4, adversarial_label=9, count=459\n",
      "attack success, original_label=3, adversarial_label=8, count=460\n",
      "attack success, original_label=5, adversarial_label=6, count=461\n",
      "attack success, original_label=0, adversarial_label=4, count=462\n",
      "attack success, original_label=2, adversarial_label=0, count=463\n",
      "attack success, original_label=2, adversarial_label=3, count=464\n",
      "attack success, original_label=6, adversarial_label=8, count=465\n",
      "attack success, original_label=9, adversarial_label=4, count=466\n",
      "attack success, original_label=1, adversarial_label=8, count=467\n",
      "attack success, original_label=6, adversarial_label=5, count=468\n",
      "attack success, original_label=9, adversarial_label=8, count=469\n",
      "attack success, original_label=1, adversarial_label=8, count=470\n",
      "attack success, original_label=3, adversarial_label=8, count=471\n",
      "attack success, original_label=7, adversarial_label=9, count=472\n",
      "attack success, original_label=0, adversarial_label=8, count=473\n",
      "attack success, original_label=6, adversarial_label=5, count=474\n",
      "attack success, original_label=8, adversarial_label=0, count=475\n",
      "attack success, original_label=2, adversarial_label=6, count=476\n",
      "attack success, original_label=2, adversarial_label=3, count=477\n",
      "attack success, original_label=0, adversarial_label=9, count=478\n",
      "attack success, original_label=8, adversarial_label=5, count=479\n",
      "attack success, original_label=9, adversarial_label=4, count=480\n",
      "orig_label=9 adv_label=4 decoded_label=4\n",
      "attack success, original_label=6, adversarial_label=4, count=481\n",
      "attack success, original_label=7, adversarial_label=9, count=482\n",
      "attack success, original_label=6, adversarial_label=0, count=483\n",
      "orig_label=6 adv_label=0 decoded_label=0\n",
      "attack success, original_label=9, adversarial_label=4, count=484\n",
      "attack success, original_label=6, adversarial_label=5, count=485\n",
      "attack success, original_label=7, adversarial_label=9, count=486\n",
      "attack success, original_label=8, adversarial_label=4, count=487\n",
      "attack success, original_label=4, adversarial_label=9, count=488\n",
      "attack success, original_label=4, adversarial_label=9, count=489\n",
      "attack success, original_label=9, adversarial_label=8, count=490\n",
      "attack success, original_label=0, adversarial_label=8, count=491\n",
      "attack success, original_label=2, adversarial_label=8, count=492\n",
      "attack success, original_label=9, adversarial_label=4, count=493\n",
      "attack success, original_label=9, adversarial_label=4, count=494\n",
      "attack success, original_label=1, adversarial_label=8, count=495\n",
      "attack success, original_label=7, adversarial_label=3, count=496\n",
      "attack success, original_label=0, adversarial_label=9, count=497\n",
      "attack success, original_label=4, adversarial_label=8, count=498\n",
      "attack success, original_label=1, adversarial_label=8, count=499\n",
      "attack success, original_label=7, adversarial_label=9, count=500\n",
      "orig_label=7 adv_label=9 decoded_label=1\n",
      "attack success, original_label=7, adversarial_label=3, count=501\n",
      "attack success, original_label=6, adversarial_label=4, count=502\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "attack success, original_label=9, adversarial_label=4, count=503\n",
      "attack success, original_label=9, adversarial_label=8, count=504\n",
      "attack success, original_label=1, adversarial_label=8, count=505\n",
      "attack success, original_label=4, adversarial_label=9, count=506\n",
      "attack success, original_label=4, adversarial_label=9, count=507\n",
      "attack success, original_label=2, adversarial_label=1, count=508\n",
      "attack success, original_label=6, adversarial_label=4, count=509\n",
      "attack success, original_label=8, adversarial_label=6, count=510\n",
      "attack success, original_label=4, adversarial_label=9, count=511\n",
      "attack success, original_label=3, adversarial_label=9, count=512\n",
      "attack success, original_label=5, adversarial_label=9, count=513\n",
      "attack success, original_label=8, adversarial_label=6, count=514\n",
      "attack success, original_label=2, adversarial_label=3, count=515\n",
      "attack success, original_label=7, adversarial_label=9, count=516\n",
      "attack success, original_label=0, adversarial_label=9, count=517\n",
      "attack success, original_label=8, adversarial_label=5, count=518\n",
      "attack success, original_label=5, adversarial_label=8, count=519\n",
      "attack success, original_label=8, adversarial_label=1, count=520\n",
      "attack success, original_label=0, adversarial_label=9, count=521\n",
      "attack success, original_label=9, adversarial_label=5, count=522\n",
      "attack success, original_label=9, adversarial_label=7, count=523\n",
      "attack success, original_label=7, adversarial_label=4, count=524\n",
      "attack success, original_label=9, adversarial_label=8, count=525\n",
      "attack success, original_label=5, adversarial_label=6, count=526\n",
      "attack success, original_label=8, adversarial_label=3, count=527\n",
      "attack success, original_label=2, adversarial_label=8, count=528\n",
      "attack success, original_label=8, adversarial_label=3, count=529\n",
      "attack success, original_label=5, adversarial_label=3, count=530\n",
      "attack success, original_label=8, adversarial_label=3, count=531\n",
      "attack success, original_label=2, adversarial_label=9, count=532\n",
      "attack success, original_label=9, adversarial_label=8, count=533\n",
      "attack success, original_label=0, adversarial_label=6, count=534\n",
      "attack success, original_label=1, adversarial_label=8, count=535\n",
      "attack success, original_label=7, adversarial_label=9, count=536\n",
      "attack success, original_label=5, adversarial_label=9, count=537\n",
      "attack success, original_label=6, adversarial_label=0, count=538\n",
      "attack success, original_label=3, adversarial_label=9, count=539\n",
      "attack success, original_label=3, adversarial_label=5, count=540\n",
      "attack success, original_label=2, adversarial_label=4, count=541\n",
      "attack success, original_label=4, adversarial_label=9, count=542\n",
      "attack success, original_label=5, adversarial_label=8, count=543\n",
      "attack success, original_label=2, adversarial_label=8, count=544\n",
      "attack success, original_label=5, adversarial_label=0, count=545\n",
      "attack success, original_label=9, adversarial_label=8, count=546\n",
      "attack success, original_label=0, adversarial_label=9, count=547\n",
      "attack success, original_label=1, adversarial_label=8, count=548\n",
      "attack success, original_label=6, adversarial_label=5, count=549\n",
      "attack success, original_label=8, adversarial_label=3, count=550\n",
      "attack success, original_label=7, adversarial_label=3, count=551\n",
      "attack success, original_label=6, adversarial_label=4, count=552\n",
      "attack success, original_label=6, adversarial_label=4, count=553\n",
      "orig_label=6 adv_label=4 decoded_label=4\n",
      "attack success, original_label=6, adversarial_label=8, count=554\n",
      "attack success, original_label=7, adversarial_label=9, count=555\n",
      "attack success, original_label=4, adversarial_label=9, count=556\n",
      "attack success, original_label=5, adversarial_label=8, count=557\n",
      "attack success, original_label=2, adversarial_label=8, count=558\n",
      "attack success, original_label=7, adversarial_label=8, count=559\n",
      "attack success, original_label=9, adversarial_label=8, count=560\n",
      "attack success, original_label=2, adversarial_label=4, count=561\n",
      "attack success, original_label=3, adversarial_label=5, count=562\n",
      "attack success, original_label=6, adversarial_label=4, count=563\n",
      "attack success, original_label=2, adversarial_label=1, count=564\n",
      "attack success, original_label=5, adversarial_label=9, count=565\n",
      "attack success, original_label=0, adversarial_label=9, count=566\n",
      "attack success, original_label=2, adversarial_label=3, count=567\n",
      "attack success, original_label=0, adversarial_label=9, count=568\n",
      "attack success, original_label=9, adversarial_label=4, count=569\n",
      "attack success, original_label=5, adversarial_label=9, count=570\n",
      "attack success, original_label=8, adversarial_label=2, count=571\n",
      "attack success, original_label=4, adversarial_label=8, count=572\n",
      "attack success, original_label=7, adversarial_label=9, count=573\n",
      "attack success, original_label=3, adversarial_label=8, count=574\n",
      "attack success, original_label=6, adversarial_label=0, count=575\n",
      "orig_label=6 adv_label=0 decoded_label=0\n",
      "attack success, original_label=0, adversarial_label=4, count=576\n",
      "attack success, original_label=3, adversarial_label=5, count=577\n",
      "attack success, original_label=9, adversarial_label=4, count=578\n",
      "orig_label=9 adv_label=4 decoded_label=4\n",
      "attack success, original_label=8, adversarial_label=9, count=579\n",
      "orig_label=8 adv_label=9 decoded_label=9\n",
      "attack success, original_label=4, adversarial_label=8, count=580\n",
      "attack success, original_label=2, adversarial_label=8, count=581\n",
      "orig_label=2 adv_label=8 decoded_label=7\n",
      "attack success, original_label=1, adversarial_label=8, count=582\n",
      "attack success, original_label=5, adversarial_label=3, count=583\n",
      "attack success, original_label=2, adversarial_label=8, count=584\n",
      "attack success, original_label=0, adversarial_label=8, count=585\n",
      "attack success, original_label=8, adversarial_label=5, count=586\n",
      "attack success, original_label=2, adversarial_label=3, count=587\n",
      "attack success, original_label=9, adversarial_label=4, count=588\n",
      "attack success, original_label=8, adversarial_label=5, count=589\n",
      "orig_label=8 adv_label=5 decoded_label=5\n",
      "attack success, original_label=4, adversarial_label=8, count=590\n",
      "attack success, original_label=4, adversarial_label=8, count=591\n",
      "attack success, original_label=0, adversarial_label=5, count=592\n",
      "attack success, original_label=3, adversarial_label=9, count=593\n",
      "attack success, original_label=9, adversarial_label=4, count=594\n",
      "orig_label=9 adv_label=4 decoded_label=4\n",
      "attack success, original_label=3, adversarial_label=5, count=595\n",
      "attack success, original_label=8, adversarial_label=6, count=596\n",
      "attack success, original_label=0, adversarial_label=9, count=597\n",
      "attack success, original_label=7, adversarial_label=9, count=598\n",
      "attack success, original_label=2, adversarial_label=3, count=599\n",
      "attack success, original_label=8, adversarial_label=5, count=600\n",
      "attack success, original_label=1, adversarial_label=8, count=601\n",
      "attack success, original_label=8, adversarial_label=9, count=602\n",
      "attack success, original_label=0, adversarial_label=5, count=603\n",
      "attack success, original_label=8, adversarial_label=3, count=604\n",
      "attack success, original_label=9, adversarial_label=4, count=605\n",
      "attack success, original_label=8, adversarial_label=9, count=606\n",
      "attack success, original_label=1, adversarial_label=8, count=607\n",
      "attack success, original_label=8, adversarial_label=9, count=608\n",
      "attack success, original_label=9, adversarial_label=4, count=609\n",
      "attack success, original_label=5, adversarial_label=8, count=610\n",
      "attack success, original_label=2, adversarial_label=8, count=611\n",
      "attack success, original_label=6, adversarial_label=4, count=612\n",
      "attack success, original_label=4, adversarial_label=9, count=613\n",
      "attack success, original_label=6, adversarial_label=0, count=614\n",
      "attack success, original_label=7, adversarial_label=4, count=615\n",
      "attack success, original_label=5, adversarial_label=3, count=616\n",
      "attack success, original_label=5, adversarial_label=8, count=617\n",
      "attack success, original_label=5, adversarial_label=8, count=618\n",
      "attack success, original_label=3, adversarial_label=2, count=619\n",
      "orig_label=3 adv_label=2 decoded_label=2\n",
      "attack success, original_label=9, adversarial_label=4, count=620\n",
      "attack success, original_label=2, adversarial_label=3, count=621\n",
      "orig_label=2 adv_label=3 decoded_label=3\n",
      "attack success, original_label=2, adversarial_label=0, count=622\n",
      "attack success, original_label=9, adversarial_label=4, count=623\n",
      "attack success, original_label=9, adversarial_label=4, count=624\n",
      "attack success, original_label=8, adversarial_label=0, count=625\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "attack success, original_label=5, adversarial_label=3, count=626\n",
      "orig_label=5 adv_label=3 decoded_label=6\n",
      "attack success, original_label=3, adversarial_label=8, count=627\n",
      "attack success, original_label=5, adversarial_label=9, count=628\n",
      "attack success, original_label=8, adversarial_label=5, count=629\n",
      "orig_label=8 adv_label=5 decoded_label=5\n",
      "attack success, original_label=1, adversarial_label=8, count=630\n",
      "attack success, original_label=3, adversarial_label=8, count=631\n",
      "attack success, original_label=2, adversarial_label=8, count=632\n",
      "attack success, original_label=2, adversarial_label=3, count=633\n",
      "attack success, original_label=3, adversarial_label=9, count=634\n",
      "attack success, original_label=8, adversarial_label=5, count=635\n",
      "attack success, original_label=5, adversarial_label=3, count=636\n",
      "attack success, original_label=9, adversarial_label=8, count=637\n",
      "attack success, original_label=5, adversarial_label=3, count=638\n",
      "attack success, original_label=9, adversarial_label=4, count=639\n",
      "attack success, original_label=6, adversarial_label=5, count=640\n",
      "attack success, original_label=4, adversarial_label=8, count=641\n",
      "attack success, original_label=0, adversarial_label=6, count=642\n",
      "attack success, original_label=6, adversarial_label=4, count=643\n",
      "attack success, original_label=7, adversarial_label=4, count=644\n",
      "orig_label=7 adv_label=4 decoded_label=4\n",
      "attack success, original_label=6, adversarial_label=8, count=645\n",
      "attack success, original_label=3, adversarial_label=9, count=646\n",
      "attack success, original_label=3, adversarial_label=5, count=647\n",
      "attack success, original_label=5, adversarial_label=6, count=648\n",
      "attack success, original_label=4, adversarial_label=9, count=649\n",
      "attack success, original_label=6, adversarial_label=4, count=650\n",
      "attack success, original_label=5, adversarial_label=9, count=651\n",
      "attack success, original_label=2, adversarial_label=8, count=652\n",
      "attack success, original_label=0, adversarial_label=8, count=653\n",
      "attack success, original_label=2, adversarial_label=3, count=654\n",
      "attack success, original_label=5, adversarial_label=8, count=655\n",
      "attack success, original_label=2, adversarial_label=3, count=656\n",
      "attack success, original_label=3, adversarial_label=5, count=657\n",
      "orig_label=3 adv_label=5 decoded_label=5\n",
      "attack success, original_label=7, adversarial_label=9, count=658\n",
      "attack success, original_label=3, adversarial_label=5, count=659\n",
      "orig_label=3 adv_label=5 decoded_label=5\n",
      "attack success, original_label=2, adversarial_label=3, count=660\n",
      "attack success, original_label=7, adversarial_label=9, count=661\n",
      "attack success, original_label=6, adversarial_label=8, count=662\n",
      "attack success, original_label=4, adversarial_label=8, count=663\n",
      "attack success, original_label=7, adversarial_label=9, count=664\n",
      "attack success, original_label=2, adversarial_label=8, count=665\n",
      "attack success, original_label=3, adversarial_label=5, count=666\n",
      "orig_label=3 adv_label=5 decoded_label=5\n",
      "attack success, original_label=5, adversarial_label=8, count=667\n",
      "attack success, original_label=0, adversarial_label=2, count=668\n",
      "attack success, original_label=0, adversarial_label=8, count=669\n",
      "attack success, original_label=9, adversarial_label=4, count=670\n",
      "attack success, original_label=1, adversarial_label=8, count=671\n",
      "attack success, original_label=0, adversarial_label=8, count=672\n",
      "attack success, original_label=0, adversarial_label=6, count=673\n",
      "attack success, original_label=0, adversarial_label=8, count=674\n",
      "attack success, original_label=3, adversarial_label=9, count=675\n",
      "attack success, original_label=1, adversarial_label=8, count=676\n",
      "attack success, original_label=0, adversarial_label=6, count=677\n",
      "attack success, original_label=4, adversarial_label=9, count=678\n",
      "attack success, original_label=7, adversarial_label=9, count=679\n",
      "orig_label=7 adv_label=9 decoded_label=9\n",
      "attack success, original_label=6, adversarial_label=9, count=680\n",
      "attack success, original_label=5, adversarial_label=6, count=681\n",
      "orig_label=5 adv_label=6 decoded_label=6\n",
      "attack success, original_label=1, adversarial_label=8, count=682\n",
      "attack success, original_label=7, adversarial_label=3, count=683\n",
      "attack success, original_label=8, adversarial_label=6, count=684\n",
      "attack success, original_label=6, adversarial_label=4, count=685\n",
      "attack success, original_label=9, adversarial_label=8, count=686\n",
      "attack success, original_label=3, adversarial_label=8, count=687\n",
      "attack success, original_label=5, adversarial_label=8, count=688\n",
      "attack success, original_label=2, adversarial_label=0, count=689\n",
      "orig_label=2 adv_label=0 decoded_label=0\n",
      "attack success, original_label=3, adversarial_label=8, count=690\n",
      "attack success, original_label=1, adversarial_label=8, count=691\n",
      "attack success, original_label=9, adversarial_label=4, count=692\n",
      "attack success, original_label=6, adversarial_label=4, count=693\n",
      "attack success, original_label=0, adversarial_label=9, count=694\n",
      "attack success, original_label=1, adversarial_label=8, count=695\n",
      "attack success, original_label=4, adversarial_label=9, count=696\n",
      "orig_label=4 adv_label=9 decoded_label=9\n",
      "attack success, original_label=2, adversarial_label=4, count=697\n",
      "attack success, original_label=2, adversarial_label=8, count=698\n",
      "attack success, original_label=5, adversarial_label=9, count=699\n",
      "attack success, original_label=4, adversarial_label=8, count=700\n",
      "attack success, original_label=5, adversarial_label=3, count=701\n",
      "attack success, original_label=6, adversarial_label=0, count=702\n",
      "attack success, original_label=0, adversarial_label=6, count=703\n",
      "attack success, original_label=1, adversarial_label=8, count=704\n",
      "attack success, original_label=9, adversarial_label=4, count=705\n",
      "attack success, original_label=4, adversarial_label=8, count=706\n",
      "attack success, original_label=6, adversarial_label=4, count=707\n",
      "attack success, original_label=3, adversarial_label=8, count=708\n",
      "attack success, original_label=1, adversarial_label=6, count=709\n",
      "attack success, original_label=9, adversarial_label=8, count=710\n",
      "attack success, original_label=6, adversarial_label=0, count=711\n",
      "attack success, original_label=6, adversarial_label=8, count=712\n",
      "orig_label=6 adv_label=8 decoded_label=0\n",
      "attack success, original_label=0, adversarial_label=9, count=713\n",
      "attack success, original_label=9, adversarial_label=8, count=714\n",
      "attack success, original_label=7, adversarial_label=3, count=715\n",
      "attack success, original_label=3, adversarial_label=5, count=716\n",
      "attack success, original_label=9, adversarial_label=8, count=717\n",
      "attack success, original_label=0, adversarial_label=9, count=718\n",
      "attack success, original_label=7, adversarial_label=9, count=719\n",
      "attack success, original_label=6, adversarial_label=0, count=720\n",
      "attack success, original_label=4, adversarial_label=8, count=721\n",
      "attack success, original_label=7, adversarial_label=9, count=722\n",
      "attack success, original_label=7, adversarial_label=8, count=723\n",
      "attack success, original_label=6, adversarial_label=0, count=724\n",
      "attack success, original_label=0, adversarial_label=9, count=725\n",
      "attack success, original_label=3, adversarial_label=9, count=726\n",
      "attack success, original_label=0, adversarial_label=8, count=727\n",
      "attack success, original_label=0, adversarial_label=5, count=728\n",
      "attack success, original_label=4, adversarial_label=9, count=729\n",
      "attack success, original_label=6, adversarial_label=4, count=730\n",
      "attack success, original_label=7, adversarial_label=3, count=731\n",
      "attack success, original_label=3, adversarial_label=9, count=732\n",
      "attack success, original_label=6, adversarial_label=4, count=733\n",
      "attack success, original_label=7, adversarial_label=3, count=734\n",
      "attack success, original_label=0, adversarial_label=8, count=735\n",
      "attack success, original_label=3, adversarial_label=5, count=736\n",
      "attack success, original_label=7, adversarial_label=9, count=737\n",
      "attack success, original_label=6, adversarial_label=4, count=738\n",
      "attack success, original_label=1, adversarial_label=8, count=739\n",
      "attack success, original_label=1, adversarial_label=8, count=740\n",
      "attack success, original_label=9, adversarial_label=4, count=741\n",
      "attack success, original_label=2, adversarial_label=0, count=742\n",
      "orig_label=2 adv_label=0 decoded_label=0\n",
      "attack success, original_label=9, adversarial_label=8, count=743\n",
      "attack success, original_label=6, adversarial_label=8, count=744\n",
      "attack success, original_label=9, adversarial_label=4, count=745\n",
      "attack success, original_label=8, adversarial_label=9, count=746\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "attack success, original_label=8, adversarial_label=4, count=747\n",
      "attack success, original_label=2, adversarial_label=5, count=748\n",
      "attack success, original_label=3, adversarial_label=9, count=749\n",
      "orig_label=3 adv_label=9 decoded_label=8\n",
      "attack success, original_label=4, adversarial_label=8, count=750\n",
      "attack success, original_label=3, adversarial_label=5, count=751\n",
      "attack success, original_label=2, adversarial_label=3, count=752\n",
      "attack success, original_label=8, adversarial_label=3, count=753\n",
      "attack success, original_label=7, adversarial_label=8, count=754\n",
      "attack success, original_label=8, adversarial_label=5, count=755\n",
      "attack success, original_label=8, adversarial_label=3, count=756\n",
      "attack success, original_label=4, adversarial_label=0, count=757\n",
      "attack success, original_label=5, adversarial_label=9, count=758\n",
      "attack success, original_label=8, adversarial_label=3, count=759\n",
      "attack success, original_label=5, adversarial_label=8, count=760\n",
      "attack success, original_label=8, adversarial_label=9, count=761\n",
      "attack success, original_label=6, adversarial_label=4, count=762\n",
      "attack success, original_label=1, adversarial_label=8, count=763\n",
      "attack success, original_label=3, adversarial_label=5, count=764\n",
      "attack success, original_label=1, adversarial_label=9, count=765\n",
      "attack success, original_label=7, adversarial_label=3, count=766\n",
      "attack success, original_label=3, adversarial_label=5, count=767\n",
      "attack success, original_label=8, adversarial_label=3, count=768\n",
      "attack success, original_label=0, adversarial_label=8, count=769\n",
      "attack success, original_label=8, adversarial_label=0, count=770\n",
      "attack success, original_label=3, adversarial_label=5, count=771\n",
      "attack success, original_label=0, adversarial_label=9, count=772\n",
      "attack success, original_label=0, adversarial_label=9, count=773\n",
      "attack success, original_label=0, adversarial_label=8, count=774\n",
      "attack success, original_label=4, adversarial_label=8, count=775\n",
      "attack success, original_label=7, adversarial_label=8, count=776\n",
      "attack success, original_label=2, adversarial_label=3, count=777\n",
      "orig_label=2 adv_label=3 decoded_label=3\n",
      "attack success, original_label=7, adversarial_label=3, count=778\n",
      "attack success, original_label=8, adversarial_label=6, count=779\n",
      "orig_label=8 adv_label=6 decoded_label=5\n",
      "attack success, original_label=8, adversarial_label=4, count=780\n",
      "attack success, original_label=7, adversarial_label=9, count=781\n",
      "orig_label=7 adv_label=9 decoded_label=9\n",
      "attack success, original_label=9, adversarial_label=8, count=782\n",
      "attack success, original_label=9, adversarial_label=4, count=783\n",
      "attack success, original_label=2, adversarial_label=8, count=784\n",
      "attack success, original_label=1, adversarial_label=4, count=785\n",
      "attack success, original_label=5, adversarial_label=8, count=786\n",
      "attack success, original_label=9, adversarial_label=4, count=787\n",
      "attack success, original_label=6, adversarial_label=5, count=788\n",
      "attack success, original_label=7, adversarial_label=3, count=789\n",
      "attack success, original_label=6, adversarial_label=8, count=790\n",
      "attack success, original_label=6, adversarial_label=0, count=791\n",
      "attack success, original_label=1, adversarial_label=8, count=792\n",
      "attack success, original_label=9, adversarial_label=8, count=793\n",
      "attack success, original_label=3, adversarial_label=8, count=794\n",
      "orig_label=3 adv_label=8 decoded_label=8\n",
      "attack success, original_label=6, adversarial_label=4, count=795\n",
      "attack success, original_label=5, adversarial_label=8, count=796\n",
      "attack success, original_label=2, adversarial_label=1, count=797\n",
      "attack success, original_label=0, adversarial_label=9, count=798\n",
      "attack success, original_label=5, adversarial_label=9, count=799\n",
      "attack success, original_label=3, adversarial_label=5, count=800\n",
      "attack success, original_label=2, adversarial_label=3, count=801\n",
      "attack success, original_label=0, adversarial_label=9, count=802\n",
      "attack success, original_label=8, adversarial_label=4, count=803\n",
      "attack success, original_label=0, adversarial_label=8, count=804\n",
      "attack success, original_label=6, adversarial_label=4, count=805\n",
      "attack success, original_label=5, adversarial_label=8, count=806\n",
      "attack success, original_label=7, adversarial_label=9, count=807\n",
      "orig_label=7 adv_label=9 decoded_label=9\n",
      "attack success, original_label=5, adversarial_label=9, count=808\n",
      "attack success, original_label=7, adversarial_label=3, count=809\n",
      "attack success, original_label=1, adversarial_label=8, count=810\n",
      "attack success, original_label=2, adversarial_label=8, count=811\n",
      "attack success, original_label=2, adversarial_label=3, count=812\n",
      "attack success, original_label=7, adversarial_label=9, count=813\n",
      "attack success, original_label=2, adversarial_label=3, count=814\n",
      "attack success, original_label=3, adversarial_label=5, count=815\n",
      "attack success, original_label=1, adversarial_label=4, count=816\n",
      "attack success, original_label=1, adversarial_label=4, count=817\n",
      "attack success, original_label=4, adversarial_label=6, count=818\n",
      "attack success, original_label=4, adversarial_label=0, count=819\n",
      "attack success, original_label=0, adversarial_label=9, count=820\n",
      "attack success, original_label=3, adversarial_label=9, count=821\n",
      "attack success, original_label=2, adversarial_label=3, count=822\n",
      "attack success, original_label=8, adversarial_label=5, count=823\n",
      "attack success, original_label=8, adversarial_label=5, count=824\n",
      "attack success, original_label=2, adversarial_label=8, count=825\n",
      "attack success, original_label=2, adversarial_label=3, count=826\n",
      "attack success, original_label=6, adversarial_label=4, count=827\n",
      "attack success, original_label=5, adversarial_label=8, count=828\n",
      "attack success, original_label=7, adversarial_label=9, count=829\n",
      "attack success, original_label=5, adversarial_label=6, count=830\n",
      "attack success, original_label=1, adversarial_label=8, count=831\n",
      "attack success, original_label=7, adversarial_label=3, count=832\n",
      "attack success, original_label=4, adversarial_label=8, count=833\n",
      "attack success, original_label=3, adversarial_label=5, count=834\n",
      "attack success, original_label=7, adversarial_label=3, count=835\n",
      "attack success, original_label=1, adversarial_label=8, count=836\n",
      "attack success, original_label=2, adversarial_label=8, count=837\n",
      "attack success, original_label=0, adversarial_label=6, count=838\n",
      "attack success, original_label=2, adversarial_label=8, count=839\n",
      "attack success, original_label=3, adversarial_label=8, count=840\n",
      "attack success, original_label=9, adversarial_label=8, count=841\n",
      "attack success, original_label=6, adversarial_label=8, count=842\n",
      "attack success, original_label=1, adversarial_label=8, count=843\n",
      "attack success, original_label=1, adversarial_label=4, count=844\n",
      "attack success, original_label=9, adversarial_label=4, count=845\n",
      "attack success, original_label=7, adversarial_label=9, count=846\n",
      "attack success, original_label=6, adversarial_label=0, count=847\n",
      "attack success, original_label=2, adversarial_label=3, count=848\n",
      "attack success, original_label=6, adversarial_label=8, count=849\n",
      "attack success, original_label=0, adversarial_label=9, count=850\n",
      "attack success, original_label=9, adversarial_label=8, count=851\n",
      "attack success, original_label=2, adversarial_label=3, count=852\n",
      "attack success, original_label=1, adversarial_label=8, count=853\n",
      "attack success, original_label=7, adversarial_label=9, count=854\n",
      "attack success, original_label=4, adversarial_label=8, count=855\n",
      "attack success, original_label=0, adversarial_label=8, count=856\n",
      "attack success, original_label=4, adversarial_label=8, count=857\n",
      "attack success, original_label=8, adversarial_label=5, count=858\n",
      "attack success, original_label=9, adversarial_label=8, count=859\n",
      "attack success, original_label=3, adversarial_label=5, count=860\n",
      "attack success, original_label=1, adversarial_label=8, count=861\n",
      "attack success, original_label=9, adversarial_label=8, count=862\n",
      "attack success, original_label=6, adversarial_label=8, count=863\n",
      "attack success, original_label=6, adversarial_label=0, count=864\n",
      "attack success, original_label=5, adversarial_label=3, count=865\n",
      "attack success, original_label=5, adversarial_label=9, count=866\n",
      "attack success, original_label=7, adversarial_label=3, count=867\n",
      "attack success, original_label=6, adversarial_label=4, count=868\n",
      "attack success, original_label=3, adversarial_label=6, count=869\n",
      "attack success, original_label=2, adversarial_label=8, count=870\n",
      "attack success, original_label=4, adversarial_label=8, count=871\n",
      "attack success, original_label=4, adversarial_label=9, count=872\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "attack success, original_label=1, adversarial_label=8, count=873\n",
      "attack success, original_label=3, adversarial_label=5, count=874\n",
      "attack success, original_label=7, adversarial_label=9, count=875\n",
      "attack success, original_label=9, adversarial_label=8, count=876\n",
      "attack success, original_label=9, adversarial_label=5, count=877\n",
      "orig_label=9 adv_label=5 decoded_label=5\n",
      "attack success, original_label=8, adversarial_label=5, count=878\n",
      "attack success, original_label=8, adversarial_label=0, count=879\n",
      "orig_label=8 adv_label=0 decoded_label=0\n",
      "attack success, original_label=8, adversarial_label=4, count=880\n",
      "attack success, original_label=5, adversarial_label=8, count=881\n",
      "attack success, original_label=2, adversarial_label=7, count=882\n",
      "attack success, original_label=7, adversarial_label=3, count=883\n",
      "attack success, original_label=9, adversarial_label=8, count=884\n",
      "attack success, original_label=3, adversarial_label=5, count=885\n",
      "attack success, original_label=7, adversarial_label=9, count=886\n",
      "attack success, original_label=7, adversarial_label=3, count=887\n",
      "attack success, original_label=5, adversarial_label=6, count=888\n",
      "attack success, original_label=0, adversarial_label=8, count=889\n",
      "attack success, original_label=9, adversarial_label=8, count=890\n",
      "attack success, original_label=1, adversarial_label=8, count=891\n",
      "attack success, original_label=1, adversarial_label=6, count=892\n",
      "attack success, original_label=4, adversarial_label=8, count=893\n",
      "attack success, original_label=7, adversarial_label=9, count=894\n",
      "attack success, original_label=4, adversarial_label=9, count=895\n",
      "attack success, original_label=3, adversarial_label=5, count=896\n",
      "attack success, original_label=8, adversarial_label=0, count=897\n",
      "orig_label=8 adv_label=0 decoded_label=0\n",
      "attack success, original_label=5, adversarial_label=8, count=898\n",
      "attack success, original_label=5, adversarial_label=9, count=899\n",
      "attack success, original_label=7, adversarial_label=9, count=900\n",
      "attack success, original_label=9, adversarial_label=0, count=901\n",
      "attack success, original_label=8, adversarial_label=6, count=902\n",
      "attack success, original_label=3, adversarial_label=5, count=903\n",
      "orig_label=3 adv_label=5 decoded_label=5\n",
      "attack success, original_label=6, adversarial_label=5, count=904\n",
      "attack success, original_label=4, adversarial_label=9, count=905\n",
      "attack success, original_label=5, adversarial_label=8, count=906\n",
      "attack success, original_label=1, adversarial_label=8, count=907\n",
      "attack success, original_label=5, adversarial_label=3, count=908\n",
      "attack success, original_label=8, adversarial_label=2, count=909\n",
      "attack success, original_label=2, adversarial_label=3, count=910\n",
      "attack success, original_label=1, adversarial_label=8, count=911\n",
      "attack success, original_label=2, adversarial_label=0, count=912\n",
      "attack success, original_label=9, adversarial_label=4, count=913\n",
      "attack success, original_label=5, adversarial_label=6, count=914\n",
      "attack success, original_label=2, adversarial_label=3, count=915\n",
      "attack success, original_label=7, adversarial_label=3, count=916\n",
      "attack success, original_label=7, adversarial_label=3, count=917\n",
      "attack success, original_label=1, adversarial_label=8, count=918\n",
      "attack success, original_label=5, adversarial_label=8, count=919\n",
      "attack success, original_label=1, adversarial_label=8, count=920\n",
      "attack success, original_label=5, adversarial_label=6, count=921\n",
      "attack success, original_label=6, adversarial_label=4, count=922\n",
      "attack success, original_label=2, adversarial_label=0, count=923\n",
      "attack success, original_label=2, adversarial_label=3, count=924\n",
      "attack success, original_label=6, adversarial_label=8, count=925\n",
      "attack success, original_label=1, adversarial_label=8, count=926\n",
      "attack success, original_label=1, adversarial_label=8, count=927\n",
      "attack success, original_label=9, adversarial_label=4, count=928\n",
      "attack success, original_label=5, adversarial_label=8, count=929\n",
      "attack success, original_label=4, adversarial_label=9, count=930\n",
      "attack success, original_label=6, adversarial_label=8, count=931\n",
      "attack success, original_label=1, adversarial_label=8, count=932\n",
      "attack success, original_label=9, adversarial_label=8, count=933\n",
      "attack success, original_label=4, adversarial_label=9, count=934\n",
      "attack success, original_label=0, adversarial_label=6, count=935\n",
      "orig_label=0 adv_label=6 decoded_label=6\n",
      "attack success, original_label=9, adversarial_label=4, count=936\n",
      "attack success, original_label=1, adversarial_label=8, count=937\n",
      "attack success, original_label=5, adversarial_label=6, count=938\n",
      "attack success, original_label=6, adversarial_label=4, count=939\n",
      "attack success, original_label=5, adversarial_label=8, count=940\n",
      "attack success, original_label=0, adversarial_label=8, count=941\n",
      "attack success, original_label=4, adversarial_label=9, count=942\n",
      "attack success, original_label=6, adversarial_label=0, count=943\n",
      "attack success, original_label=4, adversarial_label=8, count=944\n",
      "attack success, original_label=9, adversarial_label=4, count=945\n",
      "attack success, original_label=6, adversarial_label=0, count=946\n",
      "attack success, original_label=6, adversarial_label=4, count=947\n",
      "attack success, original_label=9, adversarial_label=8, count=948\n",
      "attack success, original_label=9, adversarial_label=4, count=949\n",
      "attack success, original_label=2, adversarial_label=8, count=950\n",
      "attack success, original_label=0, adversarial_label=8, count=951\n",
      "attack success, original_label=1, adversarial_label=8, count=952\n",
      "attack success, original_label=2, adversarial_label=8, count=953\n",
      "attack success, original_label=8, adversarial_label=7, count=954\n",
      "attack success, original_label=2, adversarial_label=8, count=955\n",
      "attack success, original_label=7, adversarial_label=8, count=956\n",
      "attack success, original_label=1, adversarial_label=8, count=957\n",
      "attack success, original_label=6, adversarial_label=4, count=958\n",
      "attack success, original_label=3, adversarial_label=9, count=959\n",
      "attack success, original_label=5, adversarial_label=6, count=960\n",
      "attack success, original_label=6, adversarial_label=5, count=961\n",
      "attack success, original_label=1, adversarial_label=8, count=962\n",
      "attack success, original_label=4, adversarial_label=7, count=963\n",
      "attack success, original_label=0, adversarial_label=9, count=964\n",
      "attack success, original_label=4, adversarial_label=7, count=965\n",
      "attack success, original_label=6, adversarial_label=8, count=966\n",
      "attack success, original_label=4, adversarial_label=6, count=967\n",
      "attack success, original_label=9, adversarial_label=4, count=968\n",
      "attack success, original_label=7, adversarial_label=8, count=969\n",
      "orig_label=7 adv_label=8 decoded_label=4\n",
      "attack success, original_label=1, adversarial_label=4, count=970\n",
      "attack success, original_label=7, adversarial_label=0, count=971\n",
      "attack success, original_label=6, adversarial_label=1, count=972\n",
      "attack success, original_label=2, adversarial_label=3, count=973\n",
      "attack success, original_label=4, adversarial_label=9, count=974\n",
      "orig_label=4 adv_label=9 decoded_label=9\n",
      "attack success, original_label=2, adversarial_label=8, count=975\n",
      "attack success, original_label=8, adversarial_label=6, count=976\n",
      "attack success, original_label=6, adversarial_label=4, count=977\n",
      "attack success, original_label=7, adversarial_label=4, count=978\n",
      "attack success, original_label=0, adversarial_label=6, count=979\n",
      "attack success, original_label=4, adversarial_label=8, count=980\n",
      "attack success, original_label=4, adversarial_label=9, count=981\n",
      "attack success, original_label=1, adversarial_label=8, count=982\n",
      "attack success, original_label=4, adversarial_label=9, count=983\n",
      "attack success, original_label=7, adversarial_label=3, count=984\n",
      "attack success, original_label=1, adversarial_label=8, count=985\n",
      "attack success, original_label=9, adversarial_label=8, count=986\n",
      "attack success, original_label=3, adversarial_label=8, count=987\n",
      "attack success, original_label=4, adversarial_label=0, count=988\n",
      "attack success, original_label=9, adversarial_label=4, count=989\n",
      "attack success, original_label=6, adversarial_label=4, count=990\n",
      "attack success, original_label=7, adversarial_label=9, count=991\n",
      "attack success, original_label=7, adversarial_label=9, count=992\n",
      "attack success, original_label=3, adversarial_label=9, count=993\n",
      "attack success, original_label=5, adversarial_label=8, count=994\n",
      "orig_label=5 adv_label=8 decoded_label=6\n",
      "attack success, original_label=1, adversarial_label=8, count=995\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "attack success, original_label=7, adversarial_label=9, count=996\n",
      "attack success, original_label=9, adversarial_label=8, count=997\n",
      "attack success, original_label=6, adversarial_label=4, count=998\n",
      "attack success, original_label=6, adversarial_label=8, count=999\n",
      "attack success, original_label=5, adversarial_label=8, count=1000\n",
      "[TEST_DATASET]: fooling_count=1000, total_count=1000, fooling_rate=1.000000 decoded_fooling_count=59  decoded_fooling_count_rate=0.059000\n",
      "fgsm attack done\n"
     ]
    }
   ],
   "source": [
    "for i, data in enumerate(test_loader):\n",
    "    inputs, labels = data\n",
    "    inputs, labels = inputs.numpy(), labels.numpy()\n",
    "\n",
    "    total_count += 1\n",
    "    adversary = Adversary(inputs, labels[0])\n",
    "\n",
    "    # FGSM non-targeted attack\n",
    "    adversary = attack(adversary, **attack_config)\n",
    "    if adversary.is_successful():\n",
    "        fooling_count += 1\n",
    "        print(\n",
    "            'attack success, original_label=%d, adversarial_label=%d, count=%d'\n",
    "            % (labels, adversary.adversarial_label, total_count))\n",
    "\n",
    "        #对抗样本保存在adversary.adversarial_example\n",
    "        #adversary_image=np.copy(adversary.adversarial_example[0])\n",
    "        adversary_image = torch.from_numpy(\n",
    "            np.copy(adversary.adversarial_example)).to(device).float()\n",
    "        pre_label = np.argmax(model(adversary_image).data.cpu().numpy())\n",
    "\n",
    "        #使用自编码器去噪\n",
    "        output = autoencoder(adversary_image)\n",
    "        output = output.view(1, 1, 28, 28)\n",
    "\n",
    "        decoded_label = np.argmax(model(output).data.cpu().numpy())\n",
    "\n",
    "        if decoded_label != labels[0]:\n",
    "            print(\"orig_label={} adv_label={} decoded_label={}\".format(\n",
    "                labels[0], pre_label, decoded_label))\n",
    "            decoded_fooling_count += 1\n",
    "\n",
    "    else:\n",
    "        print('attack failed, original_label=%d, count=%d' %\n",
    "              (labels, total_count))\n",
    "\n",
    "    if total_count >= TOTAL_NUM:\n",
    "        print(\n",
    "            \"[TEST_DATASET]: fooling_count=%d, total_count=%d, fooling_rate=%f decoded_fooling_count=%d  decoded_fooling_count_rate=%f\"\n",
    "            % (fooling_count, total_count,\n",
    "               float(fooling_count) / total_count, decoded_fooling_count,\n",
    "               float(decoded_fooling_count) / total_count))\n",
    "        break\n",
    "print(\"fgsm attack done\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
